<template>
  <!-- 新房   二手房-->
  <div class="box" @click="ycdb()">
    <heads></heads>
    <tools></tools>
    <div class="tit1">
      <div class="list">
        <div class="li" style="cursor: pointer" @click="() => {
          $router.push('/');
        }
          ">
          <img src="../../assets/logo.png" />
        </div>
        <div class="ti" :style="olds == 1 ? 'color:#64B6A8;' : ''" @click="cutHome(2, 1)">
          4S店
        </div>
        <div class="ti" :style="olds == 2 ? 'color:#64B6A8;' : ''" @click="cutHome(2, 2)">
          汽贸店
        </div>
        <div class="ti" :style="olds == 3 ? 'color:#64B6A8;' : ''" @click="cutHome(2, 3)">
          美容装饰
        </div>
        <div class="ti" :style="olds == 4 ? 'color:#64B6A8;' : ''" @click="cutHome(2, 4)">
          维修保养
        </div>
        <div class="sousuo">
          <input type="text" @keyup.enter="search" v-model="HousesPage.searchKeyword" placeholder="请输入关键字开始找店铺" />
          <p class="el-icon-search" @click="search"></p>
        </div>
        <!-- <div class="download">下载帮帮同城app</div> -->
        <!-- <downloadAppBtn></downloadAppBtn> -->
      </div>
    </div>
    <div class="bottom">
      <div class="list">
        <div class="li" v-for="(item, index) in housesList" :key="index">
          <img class="biao" @click="details(item, $event)" style="
              cursor: pointer;
              object-fit: contain;
              background-color: #00000033;
            " :src="item.storeCoverImage
              ? item.storeCoverImage
              : $img + item.houseImageDiv
              " />
          <div class="name" @click="details(item, $event)">
            <div class="t_1">
              {{ item.storeName }}
            </div>
            <div class="t_5">地址：{{ item.officeAddress.slice(6) }}</div>
            <div class="t_5" v-if="item.storeType == 1 || item.storeType == 2">
              {{ item.vehicleShelvesNumber }}辆
            </div>
            <div class="t_5" v-else>{{ item.serviceShelvesNumber }}项</div>
          </div>
          <div class="but">
            <div class="but1" @click="phoneGet(index)">
              <img src="../../assets/dianhua_lang.png" />
              <p>
                {{ item.phonestate ? item.contactPhoneNumber : "查看电话" }}
              </p>
            </div>
            <div class="but2" @click="chat(item.userId)">
              <img src="../../assets/weixin_b.png" />
              在线聊天
            </div>
          </div>
        </div>
      </div>
      <div v-if="housesTotal == 0" style="height: 450px; padding-top: 120px; box-sizing: border-box">
        <el-empty></el-empty>
      </div>
      <div class="fenye">
        <el-pagination background layout="prev, pager, next" :total="housesTotal" :current-page="HousesPage.pageNo"
          @current-change="HousesCurrentChange" :page-size="HousesPage.pageSize"></el-pagination>
      </div>
    </div>
    <floor></floor>
    <chat ref="chats"></chat>
    <div class="gotop" @click="toTop" v-show="showToTop" style="left: calc(100vw / 2 + 600px);">
      <img src="@/assets/top.png" />返回顶部
    </div>
  </div>
</template>
<script>
import floor from "../../components/floor";
import heads from "../../components/head";
import tools from "../../components/tools";
import chat from "../../components/chat.vue";

export default {
  components: {
    floor,
    heads,
    tools,
    chat,
  },
  data() {
    return {
      olds: -1,
      isshow: false,
      xuanzhong: 0,
      leibieIndex: -1,
      quyuIndex: -1,
      priceIndex: -1,
      loucIndex: -1,
      mianjiIndex: -1,

      jiaruXuan: "",
      jiaruXuan1: "",
      HousesPage: {
        pageNo: 1,
        pageSize: 10,
        searchKeyword: "",
      },
      housesList: [],
      housesTotal: 0,
      type7: [], //区域
      type8: [], //价格
      type9: [], //面积
      type10: [], //楼层
      type1: [], //类别
      recomHousesList: [], //推荐房源信息
      recomstate: false, //是否出现推荐房源
      searchtext: "",
      loginstate: false,
    };
  },
  mounted() { },
  created() {
    this.searchtext = this.$route.query.search;
    this.HousesPage.searchKeyword = this.searchtext;
    this.initOld();
    this.init();
  },
  methods: {
    initMap() {
      let data = {
        key: "ZYIBZ-6VVRW-NCURN-O6GZO-2VRAH-KIBJV",
        output: "jsonp",
      };
      this.$jsonp("https://apis.map.qq.com/ws/location/v1/ip", data).then(
        (data) => {
          // 经度
          this.HousesPage.longitude = data.result.location.lng;
          // 维度
          this.HousesPage.latitude = data.result.location.lat;
          this.getHouseInfo();
        }
      );
    },
    //开启聊天
    chat(id) {
      if (!this.loginstate) {
        this.$message({
          message: "请登录！",
          type: "error",
          offset: 120,
          duration: 2000,
        });
        return false;
      }
      this.$refs.chats.chatOpne(id);
    },
    ycdb() {
      this.isshow = false;
    },
    init() {
      this.initMap();
      // this.getDictionaries()
      this.getUser();
    },
    getUser() {
      let user = JSON.parse(localStorage.getItem("userInfo"));
      if (user != null) {
        this.loginstate = true;
      } else {
        this.loginstate = false;
      }
    },
    //查询车源门店信息
    getHouseInfo() {
      this.$getHttp("/api/mobile/vehicleOwner/getDealerHomePage", {
        ...this.HousesPage,
      }).then((data) => {
        if (data.code == 200) {
          const contrastIdList = JSON.parse(
            localStorage.getItem("contrastIdList")
          );
          //处理楼层信息
          data.dealerHomePage.pageList.forEach((e) => {
            e.phonestate = false;
            if (contrastIdList != null) {
              e.houseContrast = false;
              contrastIdList.forEach((el) => {
                if (el == e.id) {
                  e.houseContrast = true;
                }
              });
            }
            if (!e.hasOwnProperty("shop_name")) {
              e.shop_name = "个人房源";
            }
          });
          //查询是否加入对比
          this.housesList = data.dealerHomePage.pageList;
          this.housesTotal = data.dealerHomePage.pageCount;

          console.log(this.housesList, "222");
        }
      });
    },
    //查询字典(筛选条件)
    getDictionaries() {
      this.$getHttp("/mob/home/getDictionaries", { type: "7,8,9,10,1" }).then(
        (data) => {
          if (data.code == 200) {
            data.list.forEach((e) => {
              if (e.type == 7) this.type7.push(e);
              if (e.type == 8) this.type8.push(e);
              if (e.type == 9) this.type9.push(e);
              if (e.type == 10) this.type10.push(e);
              if (e.type == 1) this.type1.push(e);
            });
            console.log(data);
          }
        }
      );
    },
    phoneGet(index) {
      if (!this.loginstate) {
        this.$message({
          message: "请登录！",
          type: "error",
          offset: 120,
          duration: 2000,
        });
        return false;
      }
      // if (!this.shopInfoList[index].phonestate) {
      //    this.$postHttp('/mob/user/call',{
      // 			userId:this.shopInfoList[index].userId,
      // 			telephoneNumber:this.shopInfoList[index].contactsPhone,
      //       associationId:this.shopInfoList[index].id,
      //       type:'1'
      // 		}).then(res=>{

      // 	})
      // }
      this.housesList[index].phonestate = !this.housesList[index].phonestate;
    },
    initOld() {
      var type = this.$route.query.transactionType;
      var old = this.$route.query.newOld;
      console.log(type + ";" + old);
      // if (type == 2 && old == 2) {
      this.olds = old;
      // 1：4S店、2：汽贸店、3：美容装饰、4：维修保养
      // this.HousesPage.storeType = 1;
      this.HousesPage.storeType = old;
      // this.HousesPage.transactionType = 2
      // this.HousesPage.newOld = 2
      // }
      // if (type == 2 && old == 1) {
      // this.olds = 1;
      // this.HousesPage.storeType = 2;
      // this.HousesPage.dealerType = 2;
      // this.HousesPage.transactionType = 2
      // this.HousesPage.newOld = 1
      // }
    },
    search() {
      // if (this.searchtext.trim() != ''){
      // 	const routeLink = this.$router.resolve({
      // 				path: '/index/newDealer?search='+this.searchtext
      // 	})
      // 	window.open(routeLink.href, '_blank')
      // }
      // this.openUrl({
      //   path: "/index/houseSearch",
      //   query: {
      //     search: this.searchtext,
      //   },
      // });
      // this.HousesPage.keyword = this.searchtext;
      this.HousesPage.pageNo = 1;
      this.getHouseInfo();
    },

    titClick(index) {
      this.xuanzhong = index;
      this.HousesPage.pageNo = 1;
      if (index != 0) {
        this.HousesPage.userType = index;
        this.getHouseInfo();
        return;
      }
      delete this.HousesPage.userType;
      this.getHouseInfo();
    },
    leibieClick(item) {
      this.HousesPage.pageNo = 1;
      if (item != -1) {
        this.leibieIndex = item.valueNum;
        this.HousesPage.type = item.valueNum;
        this.getHouseInfo();
        return;
      }
      this.leibieIndex = item;
      delete this.HousesPage.type;
      this.getHouseInfo();
    },
    quyuClick(item) {
      this.HousesPage.pageNo = 1;
      if (item != -1) {
        this.quyuIndex = item.valueNum;
        this.HousesPage.region = item.valueName;

        this.getHouseInfo();
        return;
      }
      this.quyuIndex = item;
      delete this.HousesPage.region;
      this.getHouseInfo();
    },
    priceClick(item) {
      this.HousesPage.pageNo = 1;
      if (item != -1) {
        this.priceIndex = item.valueNum;
        this.HousesPage.price = item.valueName;
        this.getHouseInfo();
        return;
      }
      this.priceIndex = item;
      delete this.HousesPage.price;
      this.getHouseInfo();
    },
    mianjiClick(item) {
      this.HousesPage.pageNo = 1;
      if (item != -1) {
        this.mianjiIndex = item.valueNum;
        this.HousesPage.area = item.valueName;
        this.getHouseInfo();
        return;
      }
      this.mianjiIndex = item;
      delete this.HousesPage.area;
      this.getHouseInfo();
    },
    loucClick(item) {
      this.HousesPage.pageNo = 1;
      if (item != -1) {
        this.loucIndex = item.valueNum;
        this.HousesPage.floor = item.remarks;

        this.getHouseInfo();
        return;
      }
      this.loucIndex = item;
      delete this.HousesPage.floor;
      this.getHouseInfo();
    },
    HousesCurrentChange(e) {
      this.scrollToElement(document.querySelector(".bottom"));
      this.HousesPage.pageNo = e;
      this.housesList = [];
      this.getHouseInfo();
    },
    quxiaoduibi(id) {
      let contrastIdList = JSON.parse(localStorage.getItem("contrastIdList"));
      for (var i = 0; i < contrastIdList.length; i++) {
        if (contrastIdList[i] == id) {
          contrastIdList.splice(i, 1);
        }
      }
      localStorage.setItem("contrastIdList", JSON.stringify(contrastIdList));
      this.housesList.forEach((e) => {
        if (e.id == id) {
          e.houseContrast = false;
        }
      });
      this.$message({
        message: "已取消对比！",
        type: "error",
        offset: 120,
        duration: 2000,
      });
    },
    duibiqx(id) {
      if (!this.loginstate) {
        this.$message({
          message: "请登录！",
          type: "error",
          offset: 120,
          duration: 2000,
        });
        return false;
      }
      this.quxiaoduibi(id);
    },
    details(item, event) {
      //现在没数据，假造数据
      if (item.storeType == 1 || item.storeType == 2) {
        this.openUrl({
          path: "/index/newDealerDetails",
          query: {
            id: item.id,
          },
        });
      } else {
        this.openUrl({
          path: "/index/ownerServiceDetails",
          query: {
            id: item.id,
          },
        });
      }
    },
    cutHome(type, old) {
      this.HousesPage.pageNo = 1;
      // this.HousesPage.transactionType = 2
      // if (old == 1) {
      this.olds = old;
      this.HousesPage.storeType = old;
      this.HousesPage.searchKeyword = '';
      this.getHouseInfo();
      // } else {
      //   this.olds = 0;
      //   this.HousesPage.dealerType = 1;
      //   this.getHouseInfo();
      // }
    },
    shopdetails(item) {
      if (item.shop_name == "个人房源") {
        this.$message({
          message: "个人房源！",
          type: "error",
          offset: 120,
          duration: 2000,
        });
      } else {
        this.openUrl({
          path: "/index/ShopDetails",
          query: {
            id: item.shop_id,
          },
        });
      }
    },
    toAgent(id) {
      this.openUrl({
        path: "/index/goldConsultant",
        query: {
          id: id,
        },
      });
    },
  },
};
</script>
<style lang="less" scoped>
.box {
  position: relative;
  padding-bottom: 200px;
}

.tit1 {
  width: 100%;
  height: 120px;
  background-color: #f2f2f2;

  .list {
    width: 1200px;
    margin-left: 50%;
    padding-top: 32px;
    transform: translateX(-50%);
    background-color: #f2f2f2;

    div {
      display: inline-block;
      vertical-align: middle;
      font-size: 20px;
      color: #333333;
      margin-right: 40px;
      cursor: pointer;
    }

    .li {
      font-size: 28px;
      color: #64b6a8;
      margin-right: 60px;

      img {
        /* width: 60px;
					height: 60px; */
      }

      span {
        vertical-align: middle;
      }
    }

    .sousuo {
      position: relative;
      display: inline-block;
      vertical-align: middle;
      width: 380px;
      height: 50px;
      background: #ffffff;
      border-radius: 4px;
      font-size: 18px;
      overflow: hidden;

      input {
        width: 300px;
        height: 55px;
        line-height: 55px;
        text-indent: 16px;
        font-size: 18px;
      }

      img {
        width: 25px;
        height: 25px;
        margin-left: 20px;
        cursor: pointer;
      }

      p {
        position: absolute;
        top: 0;
        right: 0;
        width: 80px;
        height: 55px;
        background-color: #64b6a8;
        text-align: center;
        line-height: 55px;
        font-size: 24px;
        cursor: pointer;
        color: #ffffff;
      }
    }

    .download {
      width: 200px;
      height: 50px;
      background-color: #64b6a8;
      border-radius: 6px;
      color: #fff;
      text-align: center;
      line-height: 50px;
    }

    .but {
      display: inline-block;
      width: 200px;
      height: 50px;
      background: #64b6a8;
      border-radius: 6px;
      text-align: center;
      line-height: 50px;
      color: #fff;
    }
  }
}

.saixuan {
  color: #333;
  width: 1200px;
  margin-left: 50%;
  transform: translateX(-50%);
  font-size: 0;
  margin-top: 40px;
  padding-bottom: 20px;

  .li {
    .p1 {
      display: inline-block;
      width: 70px;
      font-size: 16px;
      font-weight: 600;
      margin-right: 32px;
      vertical-align: top;
    }

    .p2 {
      display: inline-block;
      font-size: 16px;
      margin-right: 32px;
      vertical-align: top;
      cursor: pointer;
    }

    div {
      display: inline-block;
      font-size: 16px;
      margin-right: 30px;
      vertical-align: top;
      margin-bottom: 10px;
    }

    .list {
      width: 940px;

      div {
        cursor: pointer;
      }
    }

    .xuan {
      color: #64b6a8;
    }
  }
}

.bottom {
  width: 1200px;
  margin-left: 50%;
  transform: translateX(-50%);
  color: #333333;
  margin-top: 50px;

  .tit {
    font-weight: 600;
    font-size: 32px;
    margin-bottom: 24px;
  }

  .list {
    width: 100%;

    .li {
      position: relative;
      padding-bottom: 24px;
      margin-bottom: 24px;
      border-bottom: 1px solid #e0e0e0;

      .biao {
        width: 300px;
        height: 200px;
        border-radius: 10px;
      }

      .duibi {
        position: absolute;
        width: 300px;
        height: 200px;
        top: 0;
        left: 0;
        background-color: rgba(51, 51, 51, 0.64);
        cursor: pointer;

        p {
          position: absolute;
          width: 130px;
          height: 48px;
          line-height: 48px;
          text-align: center;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          border-radius: 24px;
          color: #fff;
          border: 2px solid #ffffff;
          font-size: 21px;
        }
      }

      .name {
        display: inline-block;
        vertical-align: top;
        margin-left: 24px;
        position: relative;
        height: 200px;
        width: 700px;
        cursor: pointer;

        .t_1 {
          position: relative;
          font-size: 26px;

          padding-bottom: 12px;

          .t_1_1 {
            position: absolute;
            width: 130px;
            height: 58px;
            top: 30px;
            z-index: 999999;
            //top: 30px;
            //right: 20px;
          }
        }

        .t_2 {
          font-size: 18px;
          color: #666666;
          margin-top: 12px;
        }

        .t_3 {
          font-size: 18px;
          color: #666666;
          margin-top: 12px;
        }

        .t_4 {
          position: absolute;
          font-size: 18px;
          color: #666666;
          bottom: 0;
          left: 0;

          img {
            width: 31px;
            height: 31px;
          }

          div {
            display: inline-block;
            //width: 90px;
            padding: 0px 5px;
            height: 30px;
            background: #ffffff;
            border: 1px solid #64b6a8;
            border-radius: 4px;
            text-align: center;
            line-height: 30px;
            margin-left: 24px;
            color: #64b6a8;
          }
        }

        .t_5 {
          font-size: 18px;
          font-weight: 400;
          color: #666666;
          margin-top: 30px;
        }
      }

      .qian {
        position: absolute;
        top: 62px;
        right: 0;
        width: 190px;

        .p1 {
          width: 100%;
          font-size: 32px;
          color: #e00000;
          text-align: center;
          margin-bottom: 10px;
        }

        .p2 {
          width: 100%;
          font-size: 18px;
          color: #333333;
          text-align: center;
        }
      }
    }
  }

  .titLiat {
    width: 1200px;
    margin-left: 50%;
    transform: translateX(-50%);
    margin-bottom: 16px;

    .li {
      display: inline-block;
      vertical-align: top;
      margin-right: 40px;
      color: #333;
      cursor: pointer;

      p {
        font-size: 24px;
      }

      img {
        width: 40px;
        height: 20px;
        margin-left: 50%;
        transform: translateX(-50%);
      }
    }

    .cur {
      color: #64b6a8;
      border: 0;
      transform: scale(1.1);
    }
  }
}

.fenye {
  width: 100%;
  height: 50px;
  text-align: center;
  margin: 60px 0px;

  /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #64b6a8;
  }
}

.but {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  //width: 151px;
  top: 34px;
  right: 0px;

  .but1 {
    cursor: pointer;
    position: relative;
    box-sizing: border-box;
    display: inline-block;
    padding: 16px 18px 16px 67px;
    height: 54px;
    background: rgba(100, 182, 168, 0.08);
    border: 1px solid #64b6a8;
    border-radius: 6px;
    font-size: 16px;
    color: #64b6a8;
    margin-bottom: 17px;

    img {
      position: absolute;
      width: 40px;
      height: 40px;
      top: 7px;
      left: 19px;
    }
  }

  .but2 {
    cursor: pointer;
    width: 151px;
    position: relative;
    box-sizing: border-box;
    display: inline-block;
    align-items: center;
    padding: 16px 18px 16px 67px;
    height: 54px;
    background: #64b6a8;
    border-radius: 6px;
    font-size: 16px;
    color: #fff;

    img {
      position: absolute;
      width: 40px;
      height: 40px;
      top: 7px;
      left: 19px;
    }
  }
}
</style>
